/*
 * Copyright 2012 Alibaba.com All right reserved. This software is the
 * confidential and proprietary information of Alibaba.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Alibaba.com.
 */
package com.goldplusgold.network.lib.exception;


import com.alibaba.fastjson.JSON;

/**
 * server error such as error(500) or exception(401 403) & etc
 *
 * @author zhe.yangz 2012-1-17 下午06:57:53
 */
public class ServerStatusException extends HttpException {

    private static final long serialVersionUID = 8831634121316777078L;
    private static final String TAG = "ServerStatusException";

    /**
     * exception code
     */
    public int code;

    @SuppressWarnings("unused")
    private ServerStatusException() {
        super();
    }

    @SuppressWarnings("unused")
    private ServerStatusException(Throwable t) {
        super(t);
    }

    public ServerStatusException(int code, String msg) {
        super(msg);

        this.code = code;
    }

    public ServerStatusException(int code, String msg, Throwable t) {
        super(msg, t);

        this.code = code;
    }

    /**
     * get the server error detail
     *
     * @return null if exception, otherwise errorMsg T
     */
    public <T> T getServerError(Class<T> clazz) {
        try {
            return JSON.parseObject(getMessage(),clazz);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


}
